package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.SysUser;
import com.example.entity.vo.RoleRight;
import com.example.entity.vo.UsrRole;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2024-09-10
 */
public interface SysUserMapper extends BaseMapper<SysUser> {
    @Select("select * from sys_user where usr_name = #{usrName} and usr_password = #{usrPassword}")
    SysUser searchAllByUsrNameAndUsrPassword(@Param("usrName") String usrName,@Param("usrPassword") String usrPassword);

    @Select("select * from sys_user u INNER JOIN sys_role r on u.usr_role_id = r.role_id where u.usr_name = #{usrName}")
    UsrRole searchAllByUsrName(@Param("usrName") String usrName);

//    @Select("select r.role_name,rt.right_url from sys_user u INNER JOIN sys_role r on u.usr_role_id = r.role_id INNER JOIN sys_role_right rf on r.role_id = rf.role_rf_id INNER JOIN sys_right rt on rf.role_right_id = rt.right_rf_id")
//    List<RoleRight> selectByUsrRoleIdRoleRight();
    @Insert("insert into sys_user ( usr_name, usr_password,usr_email,usr_account) values (#{usrName},#{usrPassword},#{usrEmail},#{usrAccount});")
    Boolean insertSysUser(@Param("usrName") String usrName,@Param("usrPassword") String usrPassword,@Param("usrEmail") String usrEmail,@Param("usrAccount") String usrAccount);

    List<RoleRight> selectByUsrRoleIdRoleRight();

    @Select("select COUNT(*) as account from sys_user u INNER JOIN sys_role r on u.usr_role_id = r.role_id INNER JOIN sys_role_right rf on r.role_id = rf.role_rf_id INNER JOIN sys_right rt on rf.role_right_id = rt.right_rf_id where u.usr_name = #{usrName} and rt.right_url = #{rightUrl}")
    RoleRight selectByUsrRoleIdRole(@Param("usrName") String usrName,@Param("rightUrl") String rightUrl);
}
